package cn.edu.Day06.service.Impl;
import cn.edu.Day06.Entity.Star;
import cn.edu.Day06.GameFrame;
import cn.edu.Day06.service.StarService;

import java.awt.*;
import java.util.Random;

public class StarServiceImpl implements StarService{
    public void starDown(Star star)
    {
        star.setY(star.getY()+star.getSpeed());
        if(star.getY()>= GameFrame.H)
        {
            star.setY(0);
        }
    }

    @Override
    public Star[] createStars(Star[] stars, Random ran) {
        for (int i = 0; i < stars.length; i++) {
            Star star = stars[i] = new Star();
            //用随机数赋值.
//            System.out.println(this.getWidth());
            star.setX(ran.nextInt(GameFrame.W));
            star.setY(ran.nextInt(GameFrame.H));
            int red = ran.nextInt(256);
            int green = ran.nextInt(256);
            int blue = ran.nextInt(256);
            //色位
            star.setColor(new Color(red,green,blue));
            star.setSpeed(3);
        }
        return new Star[0];
    }

    @Override
    public void drawStar(Graphics g, Star[] stars) {
        for (int i = 0; i < stars.length; i++) {
            Star star = stars[i];
            g.setColor(star.getColor());
            g.drawString(Star.NAME,star.getX(),star.getY());
        }
    }
}
